local skel = fk.CreateSkill {
  name = "emo__zhifou",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__zhifou"] = "知否",
  [":emo__zhifou"] = "锁定技，每当你获得其他角色的牌时，你须选一项：1.摸X张牌，交给其等量于获得牌数张手牌；2.令其摸X张牌。（X为你手牌中花色数）",

  ["#emo__zhifou_give"] = "摸 %arg 张牌，交给 %dest %arg2 张手牌",
  ["#emo__zhifou_draw"] = "令 %dest 摸 %arg 张牌",
  ["#emo__zhifou-give"] = "知否：请交给 %dest %arg 张手牌",
  ["#emo__zhifou_recover"] = "令 %dest 回复1点体力",
  ["#emo__zhifou_losehp"] = "令 %dest 失去1点体力",

  ["$emo__zhifou1"] = "君知春风带暖意，可知丝丝皆妾语？",
  ["$emo__zhifou2"] = "愿将满腹相思语，化为春风拂君面。",
}

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    -- 可能死循环，限制一下发动次数
    if player:hasSkill(skel.name) and not player:isKongcheng() and player:usedSkillTimes(skel.name) < 99 then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Player.Hand and move.from and move.from ~= player and not move.from.dead then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Player.Hand or info.fromArea == Player.Equip then
              return true
            end
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local numMap = {}
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Player.Hand and move.from and move.from ~= player then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Player.Hand or info.fromArea == Player.Equip then
            numMap[move.from] = (numMap[move.from] or 0) + 1
          end
        end
      end
    end
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if player:isKongcheng() or not player:hasSkill(skel.name) then return end
      if not p.dead and numMap[p] then
        event:setCostData(self, {tos = {p}})
        self:doCost(event, p, player, numMap[p])
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to, num = target, data
    if not to or to.dead or player.dead or type(num) ~= "number" then return end
    local suits = {}
    for _, id in ipairs(player:getCardIds("h")) do
      table.insertIfNeed(suits, Fk:getCardById(id).suit)
    end
    local x = #suits
    local choice = room:askToChoice(player, {
      choices = {"#emo__zhifou_give::"..to.id..":"..x..":"..num, "#emo__zhifou_draw::"..to.id..":"..x},
      skill_name = skel.name,
    })
    if choice:startsWith("#emo__zhifou_give") then
      player:drawCards(x, skel.name)
      if not to.dead and not player:isKongcheng() then
        local cards = player:getCardIds("h")
        if #cards > num then
          cards = room:askToCards(player, {
            min_num = num, max_num = num, include_equip = false,
            skill_name = skel.name, cancelable = false, prompt = "#emo__zhifou-give::"..to.id..":"..num,
          })
        end
        room:obtainCard(to, cards, false, fk.ReasonGive, player, skel.name)
      end
    else
      to:drawCards(x, skel.name)
    end
  end,
})

return skel
